package utils

import (
	"crypto/md5"
	"encoding/hex"
	"io"
	"strconv"
	"strings"
	"time"
	"unsafe"
)

/**
 *@Author tudou
 *@Date 2019/8/24
 **/

func ParseStringToUint(id string)(uid uint){
	var uuid uint64
	uuid,_=strconv.ParseUint(id,10,64)
	uid=*(*uint)(unsafe.Pointer(&uuid))
	return uid
}


//t2现在时间>t1过期时间
func CompareTime(t1 string,t2 string)bool{
	T1,_:=time.Parse("2006-01-02 15:04:05",t1)
	T2,_:=time.Parse("2006-01-02 15:04:05",t2)
	if T1.Before(T2){
		return true
	}
	return false
}

func ParseTime(a time.Time)string{
	return a.Format("2006-01-02 15:04:05")
}

func ParseFinalPath(finalPath string)(a,b string){
	index:=strings.LastIndex(finalPath,"/")
	a=finalPath[:index+1]
	b=finalPath[index+1:]
	return
}

func ParseBytesToMB(b []byte)string{
	size:=len(b)
	size/=1024
	size/=1024
	reSize:=strconv.Itoa(size)+"MB"
	return reSize
}

func ParseUintToString(a uint)string{
	b:=strconv.Itoa(int(a))
	return string(b)
}


func ParseFileToMd5(f io.Reader)string{
	md:=md5.New()
	io.Copy(md,f)
	return hex.EncodeToString(md.Sum(nil))
}
